package homework;

public class Test02_BankAccount {
    public static void main(String[] args) {
        BankAccount b = new BankAccount("1234",
                "张三",100);
        System.out.println(b.getBalance());
        b.deposit(100);
        System.out.println(b.getBalance());
        try {
            b.withdraw(2000);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }finally {
            System.out.println(b.getBalance());
        }


    }
}
class BankAccount{
    private String accountNumber;
    private String accountName;
    private double balance;
    public void deposit(double amount){
        this.balance = this.balance+amount;
    }
    public void withdraw(double amount)
            throws Exception{
        if(this.balance<amount){
            throw new Exception("余额不够了");
        }else{
            this.balance = this.balance-amount;
        }
    }
    public double getBalance(){
        return this.balance;
    }
    public BankAccount(String accountNumber,
                       String accountName,
                       double balance) {
        this.accountNumber = accountNumber;
        this.accountName = accountName;
        this.balance = balance;
    }
}
